package com.example.parkingproject.result;

import com.example.parkingproject.code.ServiceCode;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

@Accessors(chain = true)
@Data
public class JsonResult<T> implements Serializable {

    private Integer code;
    private String  message;
    private T data;

    public static JsonResult<Void> ok(){
        return JsonResult.ok(null);
    }

    public static<T> JsonResult<T> ok(T data){
        JsonResult<T> jsonResult = new JsonResult<>();
        jsonResult.code= ServiceCode.ok.getValue() ;
        jsonResult.data = data;
        return jsonResult;
    }
    public static  JsonResult fail(ServiceCode code,String message){
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode(code.getValue());
        jsonResult.setMessage(message);
        return jsonResult;
    }
}
